473,500 Members | 1,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using words with apostrophes in filter

Hi,

I have a form with an unbound textbox for entering a name to search for with

strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = ' " &
Me.SurnameSearch & " ' "

this works fine for the filter, but however, everytime I want to serach for
a name with an apostrophe in it (e.g. O'Grady), an error would turn up.
I know it has got something to do with the apostrophe in the name confusing
with the aphostrophe used in my strSQL. But how to I overcome this problem?

Thanx
Alex
Nov 12 '05 #1
3 8341
One way I sometimes address this is to "escape" the apostrophe, like this:
Replace(Me.SurnameSearch,"'","''")
Here it is with added spaces for clarity: (Don't use it in this form,
though.)
Replace(Me.SurnameSearch," ' "," ' ' ")

HTH
- Turtle

"Alex Ng" <au**********@hotmail.com> wrote in message
news:bk**********@lust.ihug.co.nz...
Hi,

I have a form with an unbound textbox for entering a name to search for with
strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = ' " &
Me.SurnameSearch & " ' "

this works fine for the filter, but however, everytime I want to serach for a name with an apostrophe in it (e.g. O'Grady), an error would turn up.
I know it has got something to do with the apostrophe in the name confusing with the aphostrophe used in my strSQL. But how to I overcome this problem?
Thanx
Alex

Nov 12 '05 #2
"Alex Ng" <au**********@hotmail.com> wrote in message news:<bk**********@lust.ihug.co.nz>...
Hi,

I have a form with an unbound textbox for entering a name to search for with

strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = ' " &
Me.SurnameSearch & " ' "

this works fine for the filter, but however, everytime I want to serach for
a name with an apostrophe in it (e.g. O'Grady), an error would turn up.
I know it has got something to do with the apostrophe in the name confusing
with the aphostrophe used in my strSQL. But how to I overcome this problem?

Thanx
Alex


Instead os using apostrophes uses double quotes eg
strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = """ &
Me.SurnameSearch & """"
Nov 12 '05 #3
For any special characters in a string I use the chr$(x) function
where the value of x could say 34 for double quotes, 39 for single
quotes etc.

To find what should be the value of a specific special character I use
the following simple method in Excel.

1) Open a blank worksheet
2) Enter 0 in A1
3) In A2 enter the formula "=A1+1" (only what is between the double
quotes).
4) Copy the formula from A2 down the column A upto A256
5) In B1 enter the formula "=CHAR(A1)" (only what is between the
double quotes).
6) Copy the formula in B1 down the column B upto B256.

Manually search for the special character down Column B and use the
corresponding value in Column A as your value of x.

Executing the 6 steps above takes less than a minute.

So in the example below, instead of the single quotes, use Chr$(39).

Hope this helps.

Cheers!

Uttam
================

Hope this helps.

al********@hotmail.com (Alex) wrote in message news:<49**************************@posting.google. com>...
"Alex Ng" <au**********@hotmail.com> wrote in message news:<bk**********@lust.ihug.co.nz>...
Hi,

I have a form with an unbound textbox for entering a name to search for with

strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = ' " &
Me.SurnameSearch & " ' "

this works fine for the filter, but however, everytime I want to serach for
a name with an apostrophe in it (e.g. O'Grady), an error would turn up.
I know it has got something to do with the apostrophe in the name confusing
with the aphostrophe used in my strSQL. But how to I overcome this problem?

Thanx
Alex


Instead os using apostrophes uses double quotes eg
strSQL = "SELECT * FROM main " & "WHERE main.[1_surname] = """ &
Me.SurnameSearch & """"

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
2905
by: Brynn | last post by:
I want to thank the person that sent the nasty messages to my contact.asp test page ... you have inspired me !!! I have now added a bad_words filter both to my JSValidation script (going up on...
11
1982
by: Sandfordc | last post by:
I have tried several time to do this but have been unsucessful. I tried something like: myFunction(charater) str=frm.s1.value sb1=str.substring(0,charater)...
3
2757
by: Richard Hollenbeck | last post by:
I have an email field and a command button to send email. The problem is that when the email program opens up there are apostrophes around the email address that I have to manually remove before...
5
3061
by: Keith | last post by:
I've tried various combinations of quotation marks and asterisks but I can't see to get the syntax right. Could someone post a working example? Many thanks. Keith.
4
1790
by: Thomas | last post by:
I want to be able to implement a filter that manipulates the output from the server... Maybe replacing some words, or highlighting a search string, or some other fancy feature... I want to make...
2
5005
by: engwar1 | last post by:
I'm building a page for a website that will allow for anonymous users to post comments. I want to filter out words deemed offensive or obscene. I know HOW to build this feature but I'm wondering if...
2
1533
by: ChianHsieh | last post by:
Hi, I face some problem that I want to filter the all words in HTML. Example: Before Filter: <div id="pp"hello man <br/Thank's for your answer. </div> After Filter:
3
5059
by: Tracey | last post by:
Is there a way to include the quote mark/character when using the MessageBox.Show? In other words is there an alternative/secondary delimiter for strings in VB2005? <"denotes the desired...
0
1958
by: mark r | last post by:
Hi there... im on with my shoutbox again only now i want to add a bad words filter. ive got the following code off a website and would appreciate someone showing me how to integrate it into my...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7183
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7235
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5491
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4614
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1431
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
317
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.